package demo4;

import java.util.Objects;

/**
 * @Author 12629
 * @Description：
 */
class Person {
    public String name;
    public int age;
    public Person() {

    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
/*public boolean equals(Object obj) {
        Person tmp = (Person) obj;
        return this.name.equals(tmp.name) && this.age == tmp.age;
    }*/
}
class Student extends Person {

}
public class Test {

    public static void main(String[] args) {
        Person person1 = new Person("bit",10);

        Person person2 = new Person("bit",10);


        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());

        //System.out.println(person1.equals(person1));



    }
    public static void main2(String[] args) {
        Person person = new Person();
        person.name = "bit";
        System.out.println(person);

    }
    public static void main1(String[] args) {
        Object obj = new Person();
        Object obj2 = new Student();

    }
}
